package com.zjp.basetypes;

import cn.hutool.core.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
@Service
public class RedisBitmaps {
    public static final String BIT_KEY = "bit:";

    @Autowired
    private JedisPool jedisPool;


    public void test(){
        try (Jedis resource = jedisPool.getResource()) {
            Boolean setbit = resource.setbit(BIT_KEY + DateUtil.today(), 0, "1");
            System.out.println(setbit);
            Assert.isTrue(setbit,"setbit err");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void test1() {
        try (Jedis resource
                     = jedisPool.getResource()) {
            Boolean getbit = resource.getbit(BIT_KEY + DateUtil.today(), 9);
            System.out.println(getbit);
            Assert.isTrue(getbit,"setbit err");
        }catch (Exception e) {
            e.printStackTrace();
        }

    }  public void test2() {
        try (Jedis resource
                     = jedisPool.getResource()) {
            Long bitcount = resource.bitcount(BIT_KEY + DateUtil.today());
            System.out.println("bitcount "+bitcount);

        }catch (Exception e) {
            e.printStackTrace();
        }

    }public void test3() {
        try (Jedis resource
                     = jedisPool.getResource()) {
            Long bitcount = resource.bitcount(BIT_KEY + DateUtil.today(), 0, 50);
            System.out.println("bitcount "+bitcount);

        }catch (Exception e) {
            e.printStackTrace();
        }

    }
    public void test4() {
        try (Jedis resource
                     = jedisPool.getResource()) {
            Long bitpos = resource.bitpos(BIT_KEY + DateUtil.today(),false);
            System.out.println("bitpos "+bitpos);

        }catch (Exception e) {
            e.printStackTrace();
        }

    }






}
